--[[
 -- *名称:FlyScoreLayer
 -- *描述:结算飘分层
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-15
 -- *修改日期:2017-11-15
 ]]
local CURRENT_MODULE_NAME = ...
local FlyScoreLayer = class("FlyScoreLayer", PokerViewBase)
--[[
 界面处理需要保证就算是错误数据也做到不崩溃
 在获取到数据的时候进行checkData操作
]]
function FlyScoreLayer:onCreate()
    self:initWithFilePath("flyscorelayer", CURRENT_MODULE_NAME);

    self:_initialize();
end
---
-- 返回物理按钮事件
-- @DateTime 2017-10-30
-- @return   [description]
--
function FlyScoreLayer:backEvent()
    FlyScoreLayer.super.backEvent(self);
end

function FlyScoreLayer:_initialize(  )
	self._flyScoreNodes = {};
end

function FlyScoreLayer:_resetFlyNodes(  )
	for k = #self._flyScoreNodes, 1, -1 do 
		if self._flyScoreNodes[k] then 
			self._flyScoreNodes[k]:removeFromParent(true);
			self._flyScoreNodes[k] = nil;
		end
	end
end
---
 -- 播放结算飘分
 -- @DateTime 2017-11-15
 -- @param    scoreData [description]
 -- @return    [description]
 --
function FlyScoreLayer:playFlyaingScore( scoreData )
	Log.d("FlyScoreLayer:playFlyaingScore scoreData: ", scoreData);
	local config = import(".flyscoreconfig", CURRENT_MODULE_NAME);
	for k, v in ipairs(scoreData or {}) do 
		local viewId = v.viewId;
		local imgPath = v.score >= 0 and self.res_base .. "/img_num_plus.png" or self.res_base .. "/img_num_minus.png";
		self._flyScoreNodes[viewId] = ccui.TextAtlas:create([[.1]], imgPath, 27, 40, ".");
		self:addChild(self._flyScoreNodes[viewId]);
		self._flyScoreNodes[viewId]:setAnchorPoint(config[viewId].anchorpoint);
		self._flyScoreNodes[viewId]:setPosition(cc.p(config[viewId].pos.x, config[viewId].pos.y - 100));
		self._flyScoreNodes[viewId]:setOpacity(0);

		if v.score > 0 then 
			self._flyScoreNodes[viewId]:setString("." .. v.score);
		elseif v.score == 0 then 
			self._flyScoreNodes[viewId]:setString(v.score);
		else 
			self._flyScoreNodes[viewId]:setString("/" .. v.score);
		end

		local ac2 = cc.MoveBy:create(0.4, cc.p(0, 100));
		local ac3 = cc.FadeIn:create(0.4);

		self._flyScoreNodes[viewId]:runAction(cc.Sequence:create(
			cc.Spawn:create(ac2, ac3),
			cc.DelayTime:create(1.0),
			cc.CallFunc:create(function()
				self:_resetFlyNodes();
			end)
		));
	end
end

return FlyScoreLayer;